home *** CD-ROM | disk | FTP | other *** search
Wrap
#!/bin/sh # SeTpartition user-friendly rewrite Fri Dec 15 13:17:40 CST 1995 pjv # Rewrite to support filesystem plugins <david@slackware.com>, 07-May-2001 # Don't use plugins, make it work, pjv, 18-May-2001. # Generalize tempscript creation and support JFS and XFS. pjv, 30-Mar-2002 # Added Reiser4 support <maestromae@kateos.org> 11-JUN-2005 TMP=/var/log/setup/tmp NDIR=/dev/null REDIR=/dev/tty4 T_PX=/mnt export TEXTDOMAIN=SeTpartitions # FUNCTIONS # crunch() - remove extra whitespace crunch () { read STRING; echo $STRING } # make_ext2( dev, nodes, check ) - Create a new ext2 filesystem on the named # device with the specified inode density. # Parameters: dev Device node to format. # nodes Inode density (1024, 2048, 4096) # check Perform fs check (y or n) make_ext2() { # get the size of the named partition SIZE=`get_part_size $1` # output a nice status message INODE_DENSITY="`gettext "Inode density: 1 inode per"` $2 `gettext "bytes"`." dialog --title "`gettext "FORMATTING"`" \ --backtitle "`gettext "Formatting"` $1 `gettext "with filesystem"` ext2." \ --infobox "`gettext "Formatting"` $1 \n\ `gettext "Size in 1K blocks:"` $SIZE \n\ `gettext "Filesystem type:"` ext2 \n\ $INODE_DENSITY " 0 0 # do the format if mount | fgrep "$1 " 1> $NDIR 2> $NDIR ; then umount $1 2> $NDIR fi if [ "$3" = "y" ]; then mke2fs -c -i $2 $1 1> $REDIR 2> $REDIR else mke2fs -i $2 $1 1> $REDIR 2> $REDIR fi } # make_ext3( dev, nodes, check ) - Create a new ext3 filesystem on the named # device with the specified inode density. # Parameters: dev Device node to format. # nodes Inode density (1024, 2048, 4096) # check Perform fs check (y or n) make_ext3() { modprobe ext3 &>/dev/null # get the size of the named partition SIZE=`get_part_size $1` # output a nice status message INODE_DENSITY="`gettext "Inode density: 1 inode per"` $2 `gettext "bytes"`." dialog --title "`gettext "FORMATTING"`" \ --backtitle "`gettext "Formatting"` $1 `gettext "with filesystem"` ext3." \ --infobox "`gettext "Formatting"` $1 \n\ `gettext "Size in 1K blocks:"` $SIZE \n\ `gettext "Filesystem type:"` ext3 \n\ $INODE_DENSITY " 0 0 # do the format if mount | fgrep "$1 " 1> $NDIR 2> $NDIR ; then umount $1 2> $NDIR fi if [ "$3" = "y" ]; then mke2fs -j -c -i $2 $1 1> $REDIR 2> $REDIR else mke2fs -j -i $2 $1 1> $REDIR 2> $REDIR fi } # make_jfs( dev, check ) - Create a new jfs filesystem on the named # device with the specified inode density. # Parameters: dev Device node to format. # check Perform fs check (y or n) make_jfs() { modprobe jfs &>/dev/null # get the size of the named partition SIZE=`get_part_size $1` # output a nice status message dialog --title "`gettext "FORMATTING"`" \ --backtitle "`gettext "Formatting"` $1 `gettext "with filesystem"` jfs." \ --infobox "`gettext "Formatting"` $1 \n\ `gettext "Size in 1K blocks:"` $SIZE \n\ `gettext "Filesystem type:"` jfs" 0 0 # do the format if mount | fgrep "$1 " 1> $NDIR 2> $NDIR ; then umount $1 2> $NDIR fi if [ "$2" = "y" ]; then mkfs.jfs -c -q $1 1> $REDIR 2> $REDIR else mkfs.jfs -q $1 1> $REDIR 2> $REDIR fi } # make_reiserfs( dev ) - Create a new reiserfs filesystem on the named dev # Parameters: dev Device node to format. make_reiserfs() { modprobe reiserfs &>/dev/null # get the size of the named partition SIZE=`get_part_size $1` # output a nice status message dialog --title "`gettext "FORMATTING"`" \ --backtitle "`gettext "Formatting"` $1 `gettext "with filesystem"` reiserfs." \ --infobox "`gettext "Formatting"` $1 \n\ `gettext "Size in 1K blocks:"` $SIZE \n\ `gettext "Filesystem type:"` reiserfs " 0 0 # do the format if mount | fgrep "$1 " 1> $NDIR 2> $NDIR ; then umount $1 2> $NDIR fi echo "y" | mkreiserfs $1 1> $REDIR 2> $REDIR } # Make Reiser4 filesystem. make_reiser4fs() { modprobe reiser4 &>/dev/null # get the size of the named partition SIZE=`get_part_size $1` # output a nice status message dialog --title "`gettext "FORMATTING"`" \ --backtitle "`gettext "Formatting"` $1 `gettext "with filesystem"` reiser4." \ --infobox "`gettext "Formatting"` $1 \n\ `gettext "Size in 1K blocks:"` $SIZE \n\ `gettext "Filesystem type:"` reiser4 " 0 0 # do the format if mount | fgrep "$1 " 1> $NDIR 2> $NDIR ; then umount $1 2> $NDIR fi echo "y" | make_reiser4 $1 1> $REDIR 2> $REDIR } # make_xfs( dev ) - Create a new xfs filesystem on the named dev # Parameters: dev Device node to format. make_xfs() { modprobe xfs &>/dev/null # get the size of the named partition SIZE=`get_part_size $1` # output a nice status message dialog --title "`gettext "FORMATTING"`" \ --backtitle "`gettext "Formatting"` $1 `gettext "with filesystem"` xfs." \ --infobox "`gettext "Formatting"` $1 \n\ `gettext "Size in 1K blocks:"` $SIZE \n\ `gettext "Filesystem type:"` xfs " 0 0 # do the format if mount | fgrep "$1 " 1> $NDIR 2> $NDIR ; then umount $1 2> $NDIR fi mkfs.xfs -f $1 1> $REDIR 2> $REDIR } # gen_part_list() - Prints out a partition listing for the system into the gen_part_list() { export COUNT=0 cat $TMP/SeTplist | while [ 0 ]; do read PARTITION; if [ "$PARTITION" = "" ]; then break; fi # Variables, variables, variables NAME=`echo $PARTITION | crunch | cut -f 1 -d ' '` SIZE=`echo "$PARTITION" | tr -d "*" | tr -d "+" | crunch | cut -f 4 -d ' '` ALTNAME="" DEVICE=`echo "$PARTITION" | tr -d "*" | crunch | cut -f 1 -d ' '` # See if this partition is in use already if fgrep "$DEVICE " $TMP/SeTnative 1> $NDIR; then # it's been used ON=`fgrep "$DEVICE " $TMP/SeTnative | crunch | cut -f 2 -d ' '` ALTNAME="$DEVICE on $ON Linux ${SIZE}K" fi # Add a menu item if [ "$ALTNAME" = "" ]; then echo "\"$NAME\" \"Linux ${SIZE}K\" \\" >> $TMP/tempscript echo "`gettext "false"`" > $TMP/SeTSKIP # this flag is used for non-root parts else echo "\"`gettext "(IN USE)"`\" \"$ALTNAME\" \\" >> $TMP/tempscript fi done echo "\"---\" \"`gettext "(done adding partitions, continue with setup)"`\" \\" >> $TMP/tempscript echo "\"---\" \"`gettext "(done adding partitions, continue with setup)"`\" \\" >> $TMP/tempscript echo "\"---\" \"`gettext "(done adding partitions, continue with setup)"`\" \\" >> $TMP/tempscript echo "\"---\" \"`gettext "(done adding partitions, continue with setup)"`\" \\" >> $TMP/tempscript echo "\"---\" \"`gettext "(done adding partitions, continue with setup)"`\" \\" >> $TMP/tempscript echo "2> $TMP/return" >> $TMP/tempscript } # ask_format( dev ) - Asks the user if he/she wants to format the named device ask_format() { dialog --title "`gettext "FORMAT PARTITION"` $1" --menu "`gettext "If this partition has \ not been formatted, you should format it. NOTE: This will erase all data on \ it. Would you like \ to format this partition?"`" 12 70 3 \ "`gettext "Format"`" "`gettext "Quick format with no bad block checking"`" \ "`gettext "Check"`" "`gettext "Slow format that checks for bad blocks"`" \ "`gettext "No"`" "`gettext "No, do not format this partition"`" 2> $TMP/return if [ ! $? = 0 ]; then rm -f $TMP/return exit fi } # ask_nodes( dev ) - Asks the user for the inode density for the named device. ask_nodes() { dialog --title "`gettext "SELECT INODE DENSITY FOR"` $1" \ --backtitle "`gettext "Partition"` $1 `gettext "will be formatted."`" \ --menu "`gettext "If you're going to \ have many small files on your drive, then you may need more inodes than the \ default (one is used for each file entry). You can change the density to one \ inode per 2048 bytes, or even per 1024 bytes. Select '2048' or '1024', or \ just hit enter to accept the default of 4096 bytes."`" 14 70 3 \ "4096" "`gettext "1 inode per"` 4096 `gettext "bytes"`. `gettext "(default)"`" \ "2048" "`gettext "1 inode per"` 2048 `gettext "bytes"`." \ "1024" "`gettext "1 inode per"` 1024 `gettext "bytes"`." 2> $TMP/return if [ ! $? = 0 ]; then rm -f $TMP/return exit fi } # ask_fs( dev ) - Asks the user the type of filesystem to use for the named # device. Answer in $TMP/return ask_fs() { EXT2="`gettext "Ext2 is the traditional Linux file system and is fast and stable. "`" EXT3="`gettext "Ext3 is the journaling version of the Ext2 filesystem. "`" REISERFS="`gettext "ReiserFS is a journaling filesystem that stores all files and filenames in a balanced tree structure. "`" REISER4="`gettext "Reiser4 is an atomic filesystem that stores all files and filenames in a dancing tree structure. Reiser 4 is STILL UNSTABLE !!! USE IT AT YOUR OWN RISK !!! "`" JFS="`gettext "JFS is IBM's Journaled Filesystem, currently used in IBM enterprise servers. "`" XFS="`gettext "XFS is SGI's journaling filesystem that originated on IRIX. "`" DEFAULT=reiserfs echo "dialog --title \"`gettext "SELECT FILESYSTEM FOR"` $1\" \ --backtitle \"`gettext "Partition"` $1 `gettext "will be formatted."`\" \ --default-item $DEFAULT --menu \ \"`gettext "Please select the type of filesystem to use for the specified"` \n\ `gettext "device. Here are descriptions of the available filesystems:"` $EXT2 $EXT3 $JFS $REISERFS $XFS $REISER4\" \ 0 0 0 \\" > $TMP/tempscript if [ ! "$EXT2" = "" ]; then echo "\"ext2\" \"`gettext "Standard Linux ext2fs filesystem"`\" \\" >> $TMP/tempscript fi if [ ! "$EXT3" = "" ]; then echo "\"ext3\" \"`gettext "Journaling version of the ext2fs filesystem"`\" \\" >> $TMP/tempscript fi if [ ! "$JFS" = "" ]; then echo "\"jfs\" \"`gettext "IBM's Journaled Filesystem"`\" \\" >> $TMP/tempscript fi if [ ! "$REISERFS" = "" ]; then echo "\"reiserfs\" \"`gettext "Hans Reiser's Journaling Filesystem"`\" \\" >> $TMP/tempscript fi if [ ! "$REISER4" = "" ]; then echo "\"reiser4\" \"`gettext "EXPERIMENTAL !!! - Hans Reiser's Journaling Filesystem V4"`\" \\" >> $TMP/tempscript fi if [ ! "$XFS" = "" ]; then echo "\"xfs\" \"`gettext "SGI's journaling filesystem"`\" \\" >> $TMP/tempscript fi echo "2> $TMP/return" >> $TMP/tempscript . $TMP/tempscript if [ ! $? = 0 ]; then rm -f $TMP/return exit fi } # get_part_size( dev ) - Return the size in KB of the named partition. get_part_size() { Size=`probe -l | fgrep "$1 " | tr -d "*" | tr -d "+" | crunch | cut -f 4 -d ' '` echo $Size } # MAIN if [ ! -d $TMP ]; then mkdir -p $TMP fi if [ ! -r $TMP/SeTplist ]; then # Give warning? exit fi cat /dev/null >> $TMP/SeTnative echo "dialog --title \"`gettext "Select Linux installation partition:"`\" --ok-label "`gettext "Select"`" --cancel-label "`gettext "Continue"`" --menu \\ \"`gettext "Please select a partition from the following list to use for your \ root (/) Linux partition."`\" 13 70 5 \\" > $TMP/tempscript gen_part_list . $TMP/tempscript if [ ! $? = 0 ]; then rm $TMP/tempscript exit 255 # user abort fi ROOT_DEVICE="`cat $TMP/return`" rm $TMP/tempscript if [ "$ROOT_DEVICE" = "---" ]; then exit 255 fi # format root partition? ask_format $ROOT_DEVICE DOFORMAT="`cat $TMP/return`" rm -f $TMP/return if [ ! "$DOFORMAT" = "`gettext "No"`" ]; then ask_fs $ROOT_DEVICE ROOT_SYS_TYPE="`cat $TMP/return`" cat $TMP/return > $TMP/ROOTFS rm -f $TMP/return # create the filesystem if [ "$ROOT_SYS_TYPE" = "`gettext "ext2"`" ]; then ask_nodes $ROOT_DEVICE NODES="`cat $TMP/return`" rm -f $TMP/return if [ ! "$NODES" = "2048" -a ! "$NODES" = "1024" ]; then NODES=4096 fi if [ "$DOFORMAT" = "`gettext "Check"`" ]; then make_ext2 $ROOT_DEVICE $NODES "y" else make_ext2 $ROOT_DEVICE $NODES "n" fi elif [ "$ROOT_SYS_TYPE" = "`gettext "ext3"`" ]; then ask_nodes $ROOT_DEVICE NODES="`cat $TMP/return`" rm -f $TMP/return if [ ! "$NODES" = "2048" -a ! "$NODES" = "1024" ]; then NODES=4096 fi if [ "$DOFORMAT" = "`gettext "Check"`" ]; then make_ext3 $ROOT_DEVICE $NODES "y" else make_ext3 $ROOT_DEVICE $NODES "n" fi elif [ "$ROOT_SYS_TYPE" = "reiserfs" ]; then make_reiserfs $ROOT_DEVICE elif [ "$ROOT_SYS_TYPE" = "reiser4" ]; then make_reiser4fs $ROOT_DEVICE elif [ "$ROOT_SYS_TYPE" = "jfs" ]; then if [ "$DOFORMAT" = "Check" ]; then make_jfs $ROOT_DEVICE "y" else make_jfs $ROOT_DEVICE "n" fi elif [ "$ROOT_SYS_TYPE" = "xfs" ]; then make_xfs $ROOT_DEVICE fi fi # DOFORMAT? # Now, we need to mount the newly selected root device: sync # If we didn't format the partition, then we don't know what fs type it is. # So, we will try the types we know about, and let mount figure it out if all else fails: for fs in "-t ext3" "-t ext2" "-t reiserfs" "-t reiser4" "" ; do if mount $ROOT_DEVICE $T_PX $fs 1> $REDIR 2> $REDIR ; then break fi sleep 1 done sleep 1 ROOT_SYS_TYPE=`mount | grep "^$ROOT_DEVICE on " | cut -f 5 -d ' '` #echo "$ROOT_DEVICE / $ROOT_SYS_TYPE defaults 1 1" > $TMP/SeTnative printf "%-16s %-16s %-11s %-16s %-3s %s\n" "$ROOT_DEVICE" "/" "$ROOT_SYS_TYPE" "defaults" "1" "1" > $TMP/SeTnative echo $ROOT_DEVICE > $TMP/SeTrootdev # done mounting the target root partition # More than one Linux partition if [ ! "`cat $TMP/SeTplist | sed -n '2 p'`" = "" ]; then while [ 0 ]; do # next partition loop # OK, we will set this flag, and if we find an unused partition, we # change it. If it doesn't get switched, we skip the next menu. rm -f $TMP/SeTSKIP echo "true" > $TMP/SeTSKIP echo "dialog --title \"`gettext "Select other Linux partitions for /etc/fstab"`\" \ --ok-label `gettext "Select"` --cancel-label `gettext "Continue"` \ --menu \"`gettext "You seem to have more than one partition tagged as type Linux. \ You may use these to distribute your Linux system across more than \ one partition. Currently, you have"` $ROOT_DEVICE `gettext "mounted as your / partition. \ You might want to mount directories such as /home or /usr/local \ on separate partitions. You should not try to mount /etc, /sbin, or /bin on \ their own partitions since they contain utilities needed to bring the system \ up and mount partitions. Also, do not reuse a partition that you've already \ entered before. Please select one of the Linux partitions listed below, or \ if you're done, hit"` <`gettext "Continue"`>.\" 20 70 4 \\" > $TMP/tempscript gen_part_list if [ "`cat $TMP/SeTSKIP`" = "true" ]; then break; fi rm -rf $TMP/return . $TMP/tempscript if [ ! $? = 0 ]; then break; fi NEXT_PARTITION=`cat $TMP/return` if [ "$NEXT_PARTITION" = "---" ]; then break; elif [ "$NEXT_PARTITION" = "`gettext "(IN USE)"`" ]; then continue; fi # We now have the next partition, ask the user what to do with it: ask_format $NEXT_PARTITION DOFORMAT="`cat $TMP/return`" rm -f $TMP/return BACKT="`gettext "Partition"` $NEXT_PARTITION `gettext "will not be reformatted."`" if [ ! "$DOFORMAT" = "`gettext "No"`" ]; then ask_fs $NEXT_PARTITION NEXT_SYS_TYPE="`cat $TMP/return`" rm -f $TMP/return BACKT="`gettext "Partition"` $NEXT_PARTITION `gettext "will be formatted with"` $NEXT_SYS_TYPE." # create the filesystem if [ "$NEXT_SYS_TYPE" = "ext2" ]; then ask_nodes $NEXT_PARTITION NODES="`cat $TMP/return`" rm -f $TMP/return if [ ! "$NODES" = "2048" -a ! "$NODES" = "1024" ]; then NODES=4096 fi if [ "$DOFORMAT" = "`gettext "Check"`" ]; then make_ext2 $NEXT_PARTITION $NODES "y" else make_ext2 $NEXT_PARTITION $NODES "n" fi elif [ "$NEXT_SYS_TYPE" = "ext3" ]; then ask_nodes $NEXT_PARTITION NODES="`cat $TMP/return`" rm -f $TMP/return if [ ! "$NODES" = "2048" -a ! "$NODES" = "1024" ]; then NODES=4096 fi if [ "$DOFORMAT" = "`gettext "Check"`" ]; then make_ext3 $NEXT_PARTITION $NODES "y" else make_ext3 $NEXT_PARTITION $NODES "n" fi elif [ "$NEXT_SYS_TYPE" = "reiserfs" ]; then make_reiserfs $NEXT_PARTITION elif [ "$NEXT_SYS_TYPE" = "jfs" ]; then if [ "$DOFORMAT" = "`gettext "Check"`" ]; then make_jfs $NEXT_PARTITION "y" else make_jfs $NEXT_PARTITION "n" fi elif [ "$NEXT_SYS_TYPE" = "xfs" ]; then make_xfs $NEXT_PARTITION elif [ "$NEXT_SYS_TYPE" = "reiser4" ]; then make_reiser4fs $NEXT_PARTITION fi fi # DOFORMAT? # Now ask the user where to mount this new filesystem: dialog --backtitle "$BACKT" --title \ "`gettext "SELECT MOUNT POINT FOR"` $NEXT_PARTITION" --inputbox \ "`gettext -e "OK, now you need to specify where you want the new partition mounted. \ For example, if you want to put it under /usr/local, then respond: /usr/local\n\ Where would you like to mount"` $NEXT_PARTITION ?" 11 59 2> $TMP/return if [ ! $? = 0 ]; then continue fi MTPT=`cat $TMP/return` if [ "$MTPT" = "" ]; then # abort if blank continue fi if [ "`echo "$MTPT" | cut -b1`" = " " ]; then # bail if 1st char is space continue fi if [ ! "`echo "$MTPT" | cut -b1`" = "/" ]; then # add / to start of path MTPT="/$MTPT" fi rm $TMP/return # Now, we need to mount the newly selected device: sync if [ ! -d /mnt/$MTPT ]; then mkdir -p /mnt/$MTPT fi # If we didn't format the partition, then we don't know what fs type it is. # So, we will try the types we know about, and let mount figure it out if all else fails: for fs in "-t ext3" "-t ext2" "-t reiserfs" "-t jfs" "-t xfs" "-t reiser4" "" ; do if mount $NEXT_PARTITION /mnt/$MTPT $fs 1> $REDIR 2> $REDIR ; then break fi sleep 1 done sleep 1 NEXT_SYS_TYPE=`mount | grep "^$NEXT_PARTITION on " | cut -f 5 -d ' '` #echo "$NEXT_PARTITION $MTPT $NEXT_SYS_TYPE defaults 1 1" >> $TMP/SeTnative printf "%-16s %-16s %-11s %-16s %-3s %s\n" "$NEXT_PARTITION" "$MTPT" "$NEXT_SYS_TYPE" "defaults" "1" "2" >> $TMP/SeTnative done # next partition loop fi # more than one Linux partition # Done, report to the user: echo "`gettext "Adding this information to your /etc/fstab:"`" > $TMP/tempmsg cat $TMP/SeTnative >> $TMP/tempmsg dialog --title "`gettext "DONE ADDING LINUX PARTITIONS TO /etc/fstab"`" \ --exit-label OK \ --textbox $TMP/tempmsg 15 75 # Now, move our /tmp storage onto the target partition if possible: /usr/lib/setup/migrate.sh